/* eslint-disable */
/**
 * Created by GYL on 2018/8/24
 */
import React, { Component } from 'react';
import styles from '../EventPosting.less';
import {  Input,Form,  message } from 'antd';

import MyModal from '../../../components/common/MyModal';

function generateUUID() {
    var d = new Date().getTime();
    if (window.performance && typeof window.performance.now === "function") {
        d += performance.now(); //use high-precision timer if available
    }
    var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = (d + Math.random() * 16) % 16 | 0;
        d = Math.floor(d / 16);
        return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
    });
    return uuid;
}
class Edit_file extends Component {

    constructor(props) {
        super(props)
        this.state = {
            siteName: '',
            recordId: ''
        }

    }

    componentDidMount() {
        this.setState({
            siteName: this.props.siteName,
            recordId: this.props.recordId,
        })

    }

    // 取消保存
    ModalCancel = (type) => {
        let t = this;
        t.setState({
            [type]: false,
            modalBtnLoading: false
        })
        this.props.ModalCancel()
    };



    //保存按钮事件
    onModalSave = () => {



        this.props.form.validateFields((errors, values) => {
            // console.log(errors, values)

            if(this.state.siteName){
                if(this.state.recordId){
                    this.props.onModalSave(this.state)

                }else{
                    message.warning('请填写唯一标识!')
                }

            }else{
                message.warning('请填写文件名称!')
            }

        });

    }


    onInput = (v, val) => {
        var reg = new RegExp("^[0-9]*$");
        console.log(val.target.value)
        if(v != 'recordId'){
            this.setState({
                [v]: val.target.value
            })
        }else{
            if(!reg.test(val.target.value)){
                message.warning('请输入数字!')
                return
            }else{
                this.setState({
                    [v]: val.target.value
                })
            }
        }


    }
    guid = () => {
        // console.log(generateUUID())
        this.setState({
            recordId: generateUUID()
        })
    }
    render() {
        let t = this
        let width = document.body.clientWidth;
        const height = document.body.clientHeight;
        let containerHeight = '76vh';
        let tableHeight = 310;
        if (width > 1367) {
            tableHeight = 380;
            containerHeight = '83vh';
        }
        return (

            <MyModal
                mask={false}
                width={800}
                visible={true}
                title={'文件设置'}
                footerShow={true}
                destroyOnClose={true}
                onCancel={this.ModalCancel.bind(this, 'MyModal1Visible')}
                onModalSave={this.onModalSave}
                modalBtnLoading={this.props.modalBtnLoading}
            >
                <div style={{ width: '100%' }} className={styles.Edit_file}>
                    <div style={{ marginBottom: 16 }}>
                        <span style={{ color: 'red' }}> * </span> 文件名 :
                        <Input value={this.state.siteName} onChange={this.onInput.bind(this, 'siteName')} />
                    </div>

                    <div style={{ marginBottom: 16 }}>
                        <span style={{ color: 'red' }}> * </span> 文件唯一标识 :
                        <Input  value={this.state.recordId} onChange={this.onInput.bind(this, 'recordId')} />
                    </div>

                </div>

            </MyModal>
        );


    }
}
export default Form.create()(Edit_file);

